import time
from datetime import datetime
from datetime import timedelta
import re

HTML_ORG_PATTERN = re.compile('https?://\S+\.(?:jpg|png|jpeg)', re.I)
HTML_IMG_PATTERN = re.compile('https?://(?P<URLSCHEMA>[^/]+)/(?P<FILEPATH>\S+)/(?P<FILENAME>[^/]+\.(jpg|png|jpeg))',
                              re.I)
IMG_PATTERN = re.compile('https?://(?P<URLSCHEMA>[^/]+)/(?P<FILEPATH>\S+)/(?P<FILENAME>[^/]+\.(jpg|png|jpeg))$', re.I)
# 20181121 17 17 44_3826
reImage = re.compile("image\S*", re.I)


def add_second(date_str, add_count=1):
    date_list = time.strptime(date_str, "%Y%m%d%H%M%S")
    y, m, d, H, M, S = date_list[:6]
    delta = timedelta(seconds=add_count)
    date_result = datetime(y, m, d, H, M, S) + delta
    date_result = date_result.strftime("%Y%m%d%H%M%S")
    return date_result


def extract_image_name(url):
    filename = ''
    filepath = ''
    if IMG_PATTERN.search(url):
        t = IMG_PATTERN.search(url).groupdict()
        # print(t["FILENAME"])
        filename = t["FILENAME"]
        filepath = t["FILEPATH"]
    return filename, filepath


if __name__ == '__main__':
    # print(time.time())
    # st = "20181121171744"
    # et = "20181121171750"
    # while st < et:
    #     for i in range(0, 1000):
    #         print(st + "_" + str(i))
    #     st = add_second(st)
    # url = "https://images.baixingliangfan.cn/compressedPic/20190121171258_323.jpg"
    # print(extract_image_name(url))
    # for i in range(1,7):
    #     url = "https://wxmini.baixingliangfan.cn/baixing/wxmini/homePageBelowConten?page={}".format(str(i))
    #     print(url)
    # srcImgs = ["image", "image1", "image2", "pic"]
    # for img in srcImgs:
    #     if reImage.search(img):
    #         print("match:" + img)
    #     else:
    #         print("not match:" + img)
    # goodsDetail = "<img src=\"https://images.baixingliangfan.cn/shopGoodsDetailImg/20200223/20200223142032_7384.jpg\" width=\"100%\" height=\"auto\" alt=\"\" /><img src=\"https://images.baixingliangfan.cn/shopGoodsDetailImg/20200223/20200223142032_1317.jpg\" width=\"100%\" height=\"auto\" alt=\"\" /><img src=\"https://images.baixingliangfan.cn/shopGoodsDetailImg/20200223/20200223142032_8328.png\" width=\"100%\" height=\"auto\" alt=\"\" /><img src=\"https://images.baixingliangfan.cn/shopGoodsDetailImg/20200223/20200223142032_3252.jpg\" width=\"100%\" height=\"auto\" alt=\"\" />"
    # for img_url in HTML_ORG_PATTERN.findall(goodsDetail):
    # # print(HTML_IMG_PATTERN.findall(goodsDetail))
    #     print(img_url, extract_image_name(img_url))
    # a = []
    # a.append("1")
    # b = ["2"]
    # a = a + b
    #
    # print(a)

    # source_list1 = [('image', 'https://images.baixingliangfan.cn/compressedPic/20200403102636_1291.jpg', '20200403102636_1291.jpg', 'compressedPic')]
    # source_list2 = [('image', 'https://images.baixingliangfan.cn/compressedPic/20200403102636_1291.jpg', '20200403102636_1291.jpg', 'compressedPic'), ('image1', 'https://images.baixingliangfan.cn/shopGoodsImg/20200403/20200403102636_1291.jpg', '20200403102636_1291.jpg', 'shopGoodsImg/20200403'), ('comPic', 'https://images.baixingliangfan.cn/compressedPic/20200403102636_1291.jpg', '20200403102636_1291.jpg', 'compressedPic'), ('PICTURE_ADDRESS', 'https://images.baixingliangfan.cn/advertesPicture/20200208/20200208112621_337.jpg', '20200208112621_337.jpg', 'advertesPicture/20200208')]
    #
    # source_list1 = source_list1 + source_list2
    # for ll in source_list1:
    #     print(ll)

    dic = {"a": 1, "b": 2}
    print(dic)
    dic.pop("a")
    print(dic)
